package algorithm.easy;


/**
 * @author 江岸
 * @version V1.0
 * @ClassName: TwoSumOffer57
 * @description: 输入一个递增排序的数组和一个数字s，在数组中查找两个数，使得它们的和正好是s。如果有多对数字的和等于s，则输出任意一对即可。
 * @date 2020/9/219:11
 * @since V1.0
 */
public class TwoSumOffer57 {

    public static void main(String[] args) {
        int[] nums = {2,7,11,15};
        int target = 9 ;
        int[] ints = new TwoSumOffer57().twoSum(nums, target);
        for(int i:ints){
            System.out.println(i);
        }
    }


    public int[] twoSum(int[] nums, int target) {
        int i = 0;
        int j = nums.length -1 ;
        while (true){
            if (i==j){
                int[] arr = new int[0];
                return arr;
            }
            if (nums[i]+nums[j]<target){
                i++;
                continue;
            }
            if (nums[i]+nums[j]>target){
                j--;
                continue;
            }
            if (nums[i]+nums[j]==target){
                int[] arr = {nums[i],nums[j]};
                return arr;
            }
        }
    }
}